package com.hospital.demo.mapper.libokun;



import com.hospital.demo.model.libokun.Drug;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface DrugMapper {

    //查询全部药品信息
    @Select("SELECT * from drug")
    List<Drug> SelectAllDrug();
    //按ID查询药品信息
    @Select("SELECT * from drug where drug.drid=#{drid}")
    List<Drug>SelectById(@Param("drid") Integer drid);

    //删除信息
    @Delete("delete from drug where drug.drid=#{drid}")
    Integer DelectDrug(@Param("drid") Integer drid);
    //药品信息的添加
    @Insert("INSERT into drug values(Null,#{drug.drname},#{drug.drnumber},#{drug.drtypea},#{drug.drtypeb},#{drug.drpricein},#{drug.drpriceout},#{drug.drtext})")
    List<Drug> InsertDrug(@Param("drug") Drug drug);
    //批量删除
    @Delete("<script>" +
            "delete from drug where drid in (" +
            "<foreach collection=\"cidList\" item=\"item\" separator=\",\">" +
            "#{item}" +
            "</foreach>" +
            ")" +
            "</script>")
    Integer DeleteManyDrug(@Param("cidList") List<Integer> cidList);
//药品信息的修改
    @Update("update drug d set d.drpricein=#{drpricein},d.drpriceout=#{drpriceout},d.drtext=#{drtext},d.drnumber=#{drnumber} where d.drid = #{drid}")
    List<Drug>  UpdateDrug(Drug drug);

    //按名称进行模糊查询
    @Select("SELECT * from drug where drug.drname like '%#{drname}%' ORDER BY drpriceout DESC")
    List<Drug>SelectByName(@Param("drname") String drname);

}
